//Sunday, November 29 2009
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <sstream>
#include <algorithm>

using namespace std;
//ETL
class BirthdayReminders
{
public:
	vector <string> remind(vector <string> friendNames, vector <int> birthDates, int currentDate, vector <string> occasions, vector <int> days, int K)
	{
		vector<string> v;
		for(int i=currentDate; v.size()<=K; i++)
		{
			for(int k=0; k<occasions.size() && v.size() <=K; k++)
			{
				for(int j=0; j<friendNames.size() && v.size()<=K; j++)
				{
					if((i-birthDates[j])%days[k] == 0)
					{
						string s = convertIntegerToString(i);
						s += ". " + friendNames[j] + " " + occasions[k];
						s += " (";
						s += convertIntegerToString((i-birthDates[j])/days[k]);
						s += ")";
						v.push_back(s);
					}
				}
			}
		}
		vector<string> ret;
		for(int i=0; i<K; i++)
			ret.push_back(v[i]);
		return ret;
	}
	string convertIntegerToString(int number)
	{
		stringstream s;
		s << number;
		return s.str();
	}
};
